<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="/lib/layui/css/layui.css" rel="stylesheet"/>
    <link href="/css/common.css" rel="stylesheet"/>
    <title>修改密码</title>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">修改密码</div>
                <div class="layui-card-body">
                    <form class="layui-form">
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span class="layui-color-red">*</span>&nbsp当前密码：</label>
                            <div class="layui-input-block">
                                <input class="layui-input" type="password" name="passwordOld" id="passwordOld" lay-verify="required|password"
                                       placeholder="请输入当前密码" autocomplete="off" maxlength="8">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span class="layui-color-red">*</span>&nbsp;新密码：</label>
                            <div class="layui-input-block">
                                <input class="layui-input" type="password" name="password" id="password" lay-verify="required|password"
                                       placeholder="请输入密码（6~8位字母和数字）" autocomplete="off" maxlength="8">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span class="layui-color-red">*</span>&nbsp;确认新密码：</label>
                            <div class="layui-input-block">
                                <input class="layui-input" type="password" name="passwordAgain" id="passwordAgain" lay-verify="required|password"
                                       placeholder="请输入确认密码（6~8位字母和数字）" autocomplete="off" maxlength="8">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-filter="resetSubmit" lay-submit data-url="/system/user/saveOrUpdate.do">确认修改</button>
                                <button class="layui-btn layui-btn-primary" type="button" id="cancel">取消</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/lib/layui/layui.all.js" charset="utf-8"></script>
<script src="/script/common.js" charset="utf-8"></script>
<script>
    layui.use(['baseUtil'], function () {
        var $ = layui.jquery,
            form = layui.form,
            baseUtil = layui.baseUtil;

        form.verify({
            password: function (value) {
                var reg = /^[0-9a-zA-Z]{6,8}$/;
                if (!reg.test(value)) {
                    return '密码格式不正确';
                }
            }
        });

        form.on('submit(resetSubmit)', function (data) {
            var passwordOld = $('#passwordOld').val();
            var password = $('#password').val();
            var passwordAgain = $('#passwordAgain').val();
            if (password !== passwordAgain) {
                baseUtil.msg('两次密码输入不一致');
                return false;
            }
            if (passwordOld === password) {
                baseUtil.msg('新密码与原密码不能相同');
                return false;
            }
            baseUtil.doPost('/system/confirm/change.do', data.field, function (result) {
                if (result.code === 0) {
                    baseUtil.alert(result.msg, '1', function () {
                        requireLogin();
                    });
                } else {
                    baseUtil.msg(result.msg);
                }
            });
            return false;
        });

        $('#cancel').bind('click', function () {
            parent.tabDelete('/password.html');
        });
    });
</script>
</body>
</html>
